<script>
	$(function(){

				var users = $.parseJSON(<?php echo "'" . $this->users . "'" ?>);

                
                if(users.length == 0)
				{
                    alert("Geen gebruikers geselecteerd");
                    return;
                }   

                $('#moveModal').modal('show');

                updateMiniTree();

                $("#formMoveUser").ajaxForm({
                	beforeSubmit:  preventDoubleSubmit,
                        data:  {"users[]":users},
                        success: function(responseText, statusText, xhr, $form) { 

                                if(responseText.length > 0)
                                {
                                        alert(responseText);
                                        resetDoubleSubmit();
                                }else{
                                        $('#moveModal').modal('hide');
                                        updateTree();
                                }

                } });
	});
        
        function updateMiniTree()
        {
                $("#groupminitree").jstree({ 
                        "ui" : {	
                                "initially_select" : [ "tree"+selectedGroupId ]
                        },
                        "json_data" : {
                                "ajax" : {
                                        "url" : "<?php echo $this->SE_path . '/groups/getgroup' ?>",
                                        "data" : function (n) { 
                                                return { id : n.attr ? n.attr("id") : 0 }; 
                                        },
                                        "progressive_render" : true,
                                        "progressive_unload" : true
                                }
                        },
                        "plugins" : [ "themes", "json_data","ui" ]
                }).bind("select_node.jstree", function (event, data) { 
                        selectedGroupId = data.rslt.obj.attr("groupid");
                        $("#newgid").val(selectedGroupId);
                });

        }

</script>

<form
	class="form-horizontal"
	action="<?php echo $this->SE_path . "/users/movepost" ?>"
	method="post"
	id="formMoveUser">

	<div
		class="hide SEsupermodal"
		id="moveModal">
		<div>
			<div class="modal-header">
				<a
					class="close"
					data-dismiss="modal">×</a>
				<h3 id="modaltitle">
					Verplaats
					<?php echo $this->usersCount ?> gebruikers
					naar
				</h3>
			</div>
			<div
				class="modal-body"
				style="width: 300px;">
				<fieldset>
					<input
						type="hidden"
						id="newgid"
						name="newgid">

					<div id="groupminitree">
						<!-- tree will be rendered here -->
					</div>

				</fieldset>
			</div>
			<div class="modal-footer">
				<a
					href="#"
					class="btn"
					data-dismiss="modal">Annuleren</a>
				<button
					class="btn btn-primary"
					name="submit"
					value="move"
					type="submit">Verplaatsen</button>
			</div>
		</div>
	</div>

</form>
